package net.zapasa.core.common.util;

public class StringUtil {
	
	private StringUtil() {
	}

	public static boolean esNuloOVacio(String cadena) {

		return (cadena == null || cadena.isEmpty());
	}
	
	public static String quitarAcentos(String input) {
	    // Cadena de caracteres original a sustituir.
	    String original = "áàäéèëíìïóòöúùuñÁÀÄÉÈËÍÌÏÓÒÖÚÙÜÑçÇ ";
	    // Cadena de caracteres ASCII que reemplazarán los originales.
	    String ascii = "aaaeeeiiiooouuunAAAEEEIIIOOOUUUNcC+";
	    String output = input;
	    for (int i=0; i<original.length(); i++) {
	        // Reemplazamos los caracteres especiales.
	        output = output.replace(original.charAt(i), ascii.charAt(i));
	    }//for i
	    return output;
	}

	public static String sustituir(String text, Object... params) {
		StringBuffer param = new StringBuffer(10);
		String resultado = text;

		for (int i = 0; i < params.length; i++) {
			// Limpio la cadena
			param.delete(0, param.length());

			Object p = params[i];
			resultado = resultado.replaceAll(param.append("\\{").append(i)
					.append("}").toString(),
					safeRegexReplacement(String.valueOf(p)));
		}
		return resultado;
	}

	protected static String safeRegexReplacement(String replacement) {
		if (replacement == null) {
			return "";
		}

		return replacement.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\$",
				"\\\\\\$");
	}
}
